package 树;

import java.util.Random;

public class TestPriorityQueue {
    public static void main(String[] args) {
        Random random = new Random();
        PriotityQueue<Integer> queue1 = new PriotityQueue<>();
        for (int i = 0; i < 10; i++) {
            int num = random.nextInt(100);
            System.out.print(num + " ");
            queue1.offer(num);
        }

        System.out.println("\n============");
        System.out.println(queue1);
        System.out.println("============");

        while (!queue1.isEmpty()){
            System.out.println(queue1.poll());
        }

        PriotityQueue<Ghost> queue2 = new PriotityQueue<>();
        Ghost ghost1 = new Ghost("伽椰子",200,1000);
        Ghost ghost2 = new Ghost("钟馗",2000,9000);
        Ghost ghost3 = new Ghost("吸血鬼",5000,5000);
        Ghost ghost4 = new Ghost("贞子",6000,2000);

        queue2.offer(ghost1);
        queue2.offer(ghost2);
        queue2.offer(ghost3);
        queue2.offer(ghost4);
        System.out.println(queue2);

    }
}

class Ghost implements Comparable<Ghost>{
    private String name;
    private int age;
    private int level;

    public Ghost(String name, int age, int level) {
        this.name = name;
        this.age = age;
        this.level = level;
    }

    @Override
    public String toString() {
        return "Ghost{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", level=" + level +
                '}';
    }

    @Override
    public int compareTo(Ghost other) {
        if (this.level != other.level){
            return this.level - other.level;
        }else {
            return this.age - other.age;
        }
    }
}
